package com.demon.androidbasic

import android.app.Activity
import android.app.Application
import android.content.res.Configuration
import androidx.appcompat.app.AppCompatActivity
import com.demon.androidbasic.util.L
import com.demon.androidbasic.util.language.MultiLanguageUtil
import com.demon.logger.Logger
import com.hjq.bar.TitleBar
import com.hjq.bar.style.LightBarStyle
import timber.log.Timber

abstract class BaseApplication : Application() {

    companion object {
        lateinit var sInstance: BaseApplication
        @JvmStatic
        var loginClass: Class<out AppCompatActivity>? = null
        var activityList : MutableList<Activity> = mutableListOf()

    }
    /**
     * 添加Activity
     */
    fun addActivity(activity: Activity) {
        if (!activityList.contains(activity)) {
            activityList.add(activity)
        }
    }
    /**
     * 删除Activity
     */
    fun removeActivity(activity: Activity) {
        if (activityList.contains(activity)) {
            activityList.remove(activity)
        }
    }
    /**
     * 关闭当前所有Activity
     */
    fun removeAllActivity() {
        activityList.forEach {
            it.finish()
        }
    }
    override fun onCreate() {
        super.onCreate()
        sInstance = this
        Logger.plant(Timber.DebugTree())
//        CrashReport.initCrashReport(this, BuildConfig.BUGLY_APP_ID, false)
        TitleBar.setDefaultStyle(LightBarStyle())
        L.setDeBug(BuildConfig.DEBUG)
    }

    //
    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
        MultiLanguageUtil.getInstance().updateLanguage(this, MultiLanguageUtil.getInstance().getLanguageType(this))
//    languageWork()
    }
//
//  private fun languageWork() {
//    val locale: Locale = LanguageUtil.getLocale(this)
//    LanguageUtil.updateLocale(this, locale)
//  }

}